<template>
  <div @click="setUserName('jake')">设置用户名</div>
  <div>{{state.name}}</div>
</template>

<script lang="ts">
// import { defineComponent } from 'vue';

interface DataType {
  name: string;
  age?: number;
}
import { onMounted, reactive } from 'vue';

export default {
  setup() {
    // 定义响应数据
    const user: DataType = { name: 'tom', age: 18 }
    const state = reactive(user);

    function setUserName(name: string): void {
      state.name = name;
    }

    onMounted(() => {
      setUserName('11111')
    })

    return {
      state,
      setUserName
    }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
